<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
  <link href="../cwjy/static/css/app.css" rel="stylesheet" type="text/css">
</head>
<script src="../cwjy/static/js/jquery.min.js" type="text/javascript"></script>
<script src="../cwjy/static/js/app.js" type="text/javascript"></script>
<body  style=" background: url(../cwjy/static/img/login.jpg) no-repeat center center fixed; background-size: 115%;">
<!--<body  style=" background: #ffffff no-repeat center center fixed; background-size: 115%;">-->
  <div class="container">
    <div class="row">
        <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="height: 500px;margin-top: 22%">
            <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12" style="font-size: 50px;text-align: center;font-weight: bold;text-shadow: 1px 1px 3px #000000;">宠物医院寄养系统管理员登录页面</div>
            <div class= "col-lg-12 col-md-12 col-sm-12 col-xs-12" style="margin-top: 3%">
                <form  style="font-weight: bold;font-size: 15px;text-shadow: 2px 2px 2px #cccccc">
                    <div class="mb-3 row" style="margin-left: 20%">
                        <label class="col-form-label col-sm-2 text-sm-right">账户</label>
                        <div class="col-sm-5">
                            <input type="text" class="form-control" id="username" placeholder="请输入账户">
                        </div>
                    </div>
                    <div class="mb-3 row" style="margin-left: 20%">
                        <label class="col-form-label col-sm-2 text-sm-right">密码</label>
                        <div class="col-sm-5">
                            <input type="password" class="form-control" id="password"   placeholder="请输入密码">
                        </div>
                    </div>
                <div class="form-group col-lg-12 col-md-12 col-sm-12 col-xs-12" style="margin-top: 1.5%">
                  <div class="col-sm-offset-2 col-sm-10" style="margin-left: 35%">
                    <button type="button" class="btn btn-primary" style="font-weight: bold;font-size: 20px" onclick="login()">登录</button>
                    <button type="button" class="btn btn-primary" style="font-weight: bold;font-size: 20px;margin-left: 20%">重置</button>
                  </div>
                </div>
              </form>
            </div>
        </div>
    </div>
  </div>
<!--<script type="text/javascript" src="../cwyy/static/js/login.js">

</script>-->
<script type="text/javascript">
    function login(){
        let username = $('#username').val();
        let password = $('#password').val();
        if(username === ""){
            alert("用户名为空");
            return;
        }
        if(password === ""){
            alert("密码为空")
            return;
        }
        /**请求方式post 异步*/
        $.ajax({
            type: 'post',
            async: false,            //异步请求（同步请求将会锁住浏览器，用户其他操作必须等待请求完成才可以执行）
            url: 'http://localhost:8888/cwjy/user/loginAdmin',    //请求发送到Servlet
            contentType: 'application/json;charset=UTF-8',//指定消息请求类型
            data: JSON.stringify({"username":username,"password":password}),
            timeout: 10000,    //超时10s
            success: function (res) {
                /**生出成功刷新页面*/
                if (res.data > 0) {
                    alert('登陆成功!');
                    /**刷新页面*/
                    window.location.href = 'index';
                }else {
                    if(parseInt(res.code) === 500 ){
                        alert(res.data)
                    } else {
                        alert("账户密码错误")
                    }
                }
            },
            error: function (errorMsg) {
                //请求失败时执行该函数
                alert('账号或密码错误!');
            }
        });
    }
</script>
</body>
</html>
